package cn.aopmin.controller;

import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/mail")
public class MailController {

    private final MailService mailService;

    public MailController(MailService mailService) {
        this.mailService = mailService;
    }

    @PostMapping("/send")
    public String sendMail(@RequestBody EmailRequest request) {
        mailService.sendEmail(request.getTo(), request.getSubject(), request.getText());
        return "邮件已发送";
    }

    static class EmailRequest {
        private String to;
        private String subject;
        private String text;

        // Getters and Setters
        public String getTo() { return to; }
        public void setTo(String to) { this.to = to; }

        public String getSubject() { return subject; }
        public void setSubject(String subject) { this.subject = subject; }

        public String getText() { return text; }
        public void setText(String text) { this.text = text; }
    }
}
